<?php
    class WZ_Singleton
    {
        private static $_instances;
        private static $_currentNamespace = '';

        public static function __callStatic($name, array $args) 
        {
            $name = static::$_currentNamespace . '\\' . $name;
            if(empty(static::$_instances[$name]) || !empty($args)) {
                if (class_exists($name)) {
                    $class = new \ReflectionClass($name);
                    static::$_instances[$name] = !empty($args) ? $class->newInstanceArgs($args) : $class->newInstance();
                } else {
                    throw new \RuntimeException("Class $name not found");
                }
            }
            return static::$_instances[$name];
        }
     
        public static function setNamespace ($ns = '') 
        {
            if (strpos($ns, '\\') === 0) {
                $ns = substr($ns, 1);
            }
            static::$_currentNamespace = $ns;
        }
    }